package com.secxiot.provider.user.controller;

import com.secxiot.provider.DeptApi;
import com.secxiot.provider.task.vo.SosDeptFacilityVo;
import com.secxiot.provider.user.dto.DeptDto;
import com.secxiot.provider.user.dto.UserDeptDto;
import com.secxiot.provider.user.service.DeptService;
import com.secxiot.provider.user.vo.DeptVo;
import com.secxiot.provider.user.vo.HospitalVo;
import com.secxiot.provider.user.vo.UserSimpleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RequestMapping("/depts")
@RestController
public class DeptController implements DeptApi {

    @Autowired
    private DeptService deptService;

    @GetMapping("/user")
    @Override
    public DeptDto getDeptByUserId(Long userId) {
        return deptService.getDeptByUserId(userId);
    }

    @GetMapping("/{deptId}")
    @Override
    public DeptDto getDeptByDeptId(@PathVariable Long deptId) {
        return deptService.getDeptByDeptId(deptId);
    }

    @GetMapping("/{deptId}/subdept")
    @Override
    public List<DeptDto> listSubdeptByDeptId(@PathVariable Long deptId) {
        return deptService.listSubdeptByDeptId(deptId);
    }

    @GetMapping("/hospitals")//患者经纬度   患者id
    @Override
    public List<HospitalVo> listHospitalsByUser(Long userId, BigDecimal longitude, BigDecimal latitude, String wxAppId) {
        return deptService.hospitalListByUser(userId, longitude, latitude, wxAppId);
    }

    @Override
    @GetMapping("/hospital/nearest")
    public HospitalVo getNearestHospital(BigDecimal longitude, BigDecimal latitude, Long hospitalId) {
        return deptService.getNearestHospital(longitude, latitude, hospitalId);
    }

    @Override
    @GetMapping("/hospital/detail/{id}")
    public HospitalVo getHospitalById(@RequestParam("id") Long id) {
        return deptService.getHospitalById(id);
    }

    @Override
    @GetMapping("/hospital/detailByDeptId/{deptId}")
    public HospitalVo getHospitalByDeptId(@RequestParam("deptId") Long deptId) {
        return deptService.getHospitalByDeptId(deptId);
    }

    @Override
    @GetMapping("/hospital/getHospitalDistance/detail")
    public HospitalVo getHospitalDistanceByDeptId(@RequestParam("longitude") BigDecimal longitude,
                                                  @RequestParam("latitude") BigDecimal latitude,
                                                  @RequestParam("deptId") Long deptId) {
        return deptService.getHospitalDistanceByDeptId(longitude, latitude, deptId);
    }

    @Override
    @GetMapping("/hospital/list")
    public List<HospitalVo> selectHospital() {
        return deptService.selectHospital();
    }


    @GetMapping("/sosFacility")
    @Override
    public List<SosDeptFacilityVo> sosFacility(Long deptId, Long hospitalId) {
        return deptService.SosFacility(deptId, hospitalId);
    }

    @GetMapping("/subManagers")
    @Override
    public List<UserSimpleVo> listSubManagers(@RequestParam("deptId") Long deptId) {
        return deptService.listSubManagers(deptId);
    }

    @GetMapping("/suppers")
    @Override
    public List<UserDeptDto> listSupperDeptByUserId(@RequestParam("userId") Long userId) {
        return deptService.listSupperDeptByUserId(userId);
    }

    @GetMapping("/toLeaf")
    @Override
    public List<DeptDto> listToLeafByDeptId(@RequestParam("deptId") Long deptId) {
        return deptService.listToLeafByDeptId(deptId);
    }

    /**
     * 获取parentId下的部门列表
     *
     * @param parentId
     * @return
     */
    @GetMapping("/list")
    @Override
    public List<DeptVo> listDeptByParentId(@RequestParam("parentId") Long parentId) {
        return deptService.listDeptByParentId(parentId);
    }
}
